package cn.iocoder.an.module.mold.service.recheckstatics;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.an.module.mold.controller.admin.recheckstatics.vo.*;
import cn.iocoder.an.module.mold.dal.dataobject.recheckstatics.RecheckStaticsDO;
import cn.iocoder.an.framework.common.pojo.PageResult;
import cn.iocoder.an.framework.common.pojo.PageParam;
import cn.iocoder.an.framework.common.util.object.BeanUtils;

import cn.iocoder.an.module.mold.dal.mysql.recheckstatics.RecheckStaticsMapper;

import static cn.iocoder.an.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.an.module.mold.enums.ErrorCodeConstants.*;

/**
 * 复检统计 Service 实现类
 *
 * @author ykk
 */
@Service
@Validated
public class RecheckStaticsServiceImpl implements RecheckStaticsService {

    @Resource
    private RecheckStaticsMapper recheckStaticsMapper;

    @Override
    public Long createRecheckStatics(RecheckStaticsSaveReqVO createReqVO) {
        // 插入
        RecheckStaticsDO recheckStatics = BeanUtils.toBean(createReqVO, RecheckStaticsDO.class);
        recheckStaticsMapper.insert(recheckStatics);

        // 返回
        return recheckStatics.getId();
    }

    @Override
    public void updateRecheckStatics(RecheckStaticsSaveReqVO updateReqVO) {
        // 校验存在
        validateRecheckStaticsExists(updateReqVO.getId());
        // 更新
        RecheckStaticsDO updateObj = BeanUtils.toBean(updateReqVO, RecheckStaticsDO.class);
        recheckStaticsMapper.updateById(updateObj);
    }

    @Override
    public void deleteRecheckStatics(Long id) {
        // 校验存在
        validateRecheckStaticsExists(id);
        // 删除
        recheckStaticsMapper.deleteById(id);
    }

    @Override
        public void deleteRecheckStaticsListByIds(List<Long> ids) {
        // 删除
        recheckStaticsMapper.deleteByIds(ids);
        }


    private void validateRecheckStaticsExists(Long id) {
        if (recheckStaticsMapper.selectById(id) == null) {
            throw exception(RECHECK_STATICS_NOT_EXISTS);
        }
    }

    @Override
    public RecheckStaticsDO getRecheckStatics(Long id) {
        return recheckStaticsMapper.selectById(id);
    }

    @Override
    public PageResult<RecheckStaticsDO> getRecheckStaticsPage(RecheckStaticsPageReqVO pageReqVO) {
        return recheckStaticsMapper.selectPage(pageReqVO);
    }

}